package com.bestcem.xm.award.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * EasyExcel读取监听器
 *
 * @author hang.li <hang.li@idiaoyan.com>
 * @version v1.0
 * @date 2021/12/13 17:26
 */
@Component
public class AwardEasyExcelListener<T> extends AnalysisEventListener<T> {

    /**
     * 读取数据List
     */
    private List<T> data = new LinkedList<>();

    /**
     * 表头map
     */
    private Map<Integer, String> headMap = new HashMap<>();

    @Override
    public void invoke(T t, AnalysisContext analysisContext) {
        data.add(t);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
    }

    @Override
    public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
        this.headMap.putAll(headMap);
    }

    /**
     * 获取读取的数据
     *
     * @return List
     */
    public List<T> getResult(){
        return data;
    }

    /**
     * 获取excel表头数据
     *
     * @return Map<Integer, String>
     */
    public Map<Integer, String> getHeadMap() {
        return headMap;
    }
}
